package com.system.demo.controller.leave;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.system.demo.entity.DTO.LeaveIdDTO;
import com.system.demo.entity.DTO.LeaveSearchDTO;
import com.system.demo.service.LeaveService;
import com.system.demo.tool.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/leave")
public class LeaveAdminController {

    @Autowired
    private LeaveService leaveService;


    /**
     * 管理员查看离校申请
     *
     * @param leaveSearchDTO      管理员查看申请
     * @return    返回信息
     */
    @PostMapping("/request")
    @SaCheckPermission("AbsenceApprove")
    public ResponseResult<?> requestLeave(@RequestBody LeaveSearchDTO leaveSearchDTO, int current, int size) {
        // 查询请假申请
        return leaveService.requestLeave(leaveSearchDTO,current,size);
    }


    /**
     * 管理员审批申请
     *
     * @param applicationId      需要审批的申请
     * @param isApproved         申请状态（0转为1或2，1为已审批未通过，2为已申请已通过）
     * @return    返回信息
     */
    @PostMapping("/change")
    @SaCheckPermission("AbsenceApprove")
    public ResponseResult<?> changeLeave(@RequestBody LeaveIdDTO applicationId, @RequestParam String isApproved) {
        // 修改审批状态
        return leaveService.changeLeave(applicationId,isApproved);
    }

    /**
     * 管理员审批销假
     *
     * @param applicationId      需要审批的申请
     * @param isApproved         申请状态（3转为4或5，4为已核实销假，5为夜不归宿）
     * @return    返回信息
     */
    @PostMapping("/approve")
    @SaCheckPermission("AbsenceApprove")
    public ResponseResult<?> approvalBack(@RequestBody LeaveIdDTO applicationId, @RequestParam String isApproved) {
        //审批是否已返校
        return leaveService.approvalBack(applicationId,isApproved);
    }
}
